#include "HelloNative.h"
#include "binaryzation.h"

int result=888; 

JNIEXPORT void JNICALL Java_com_start_printer_HelloJNI_setNum(JNIEnv * env, jclass jc, jint num)
{
    result+=num;
}

JNIEXPORT jint JNICALL Java_com_start_printer_HelloJNI_get(JNIEnv * env, jclass jc)
{
    return result;
}

JNIEXPORT jbyteArray JNICALL Java_com_start_printer_HelloJNI_otsu(
        JNIEnv *env,
        jclass jc,
        jint width,
        jint height,
        jbyteArray jPiexs,
        jint nThreshold) {

    jbyte* bBuffer = (*env)->GetByteArrayElements(env,jPiexs,0);
    unsigned char *data32=(unsigned char*)bBuffer;

    unsigned char *otsuData = otsu(width, height, data32, nThreshold);
    int size = width * height / 8;
    jbyteArray data1 = (*env)->NewByteArray(env,(jint)size);
    (*env)->SetByteArrayRegion(env,data1, 0, (jint)size,(jbyte*)otsuData);
    return data1;
}
